<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org"
      xmlns:sec="http://www.thymeleaf.org/thymeleaf-extras-springsecurity3" xmlns:head="http://www.w3.org/1999/html">
<head th:include="public/public_css::public_css ('盘点计划')" />

<link rel="stylesheet" type="text/css" th:href="@{/plugin/layui/css/font/iconfont.css}" media="all"/>
<link rel="stylesheet" type="text/css" th:href="@{/plugin/layui/js/layui/css/layui.css}" media="all"/>
<link rel="stylesheet" type="text/css" th:href="@{/css/main.css}" media="all"/>

<body style="background-color: #f2f2f2;">
<div class="layui-fluid larry-wrapper">
    <div class="layui-card">
        <div class="layui-row layui-col-space30">
            <div class="layui-col-xs24">
                <form class="layui-form layui-card-header  layui-card-header-auto" id="searchForm">
                    <div class="layui-inline">
                        <label class="layui-form-label">盘点编号</label>
                        <div class="layui-input-inline">
                            <input type="text" class="layui-input" id="pdbh" name="pdbh" />
                        </div>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label">盘点类型</label>

                        <select name="lx" lay-filter="aihao">
                            <option value=""></option>
                            <option value="">全部</option>
                            <option value="0">普通盘点</option>
                            <option value="1">差异盘点</option>
                        </select>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label">全仓盘点</label>
                        <select name="qcpd" lay-filter="aihao">
                            <option value=""></option>
                            <option value="">全部</option>
                            <option value="0">否</option>
                            <option value="1">是</option>
                        </select>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label">任务状态</label>
                        <select name="rwzt" lay-filter="aihao">
                            <option value=""></option>
                            <option value="">全部</option>
                            <option value="0">未生成</option>
                            <option value="1">已生成</option>
                        </select>
                    </div>


                    <div class="layui-inline inline-search-btn">
                        <a class="layui-btn layui-btn-normal" data-type="reload" id="search_button">搜索</a>
                    </div>
                    <div class="layui-inline inline-reset-btn">
                        <button type="reset" class="layui-btn layui-btn-primary" style="background-color: #1e9fff;color: white;"><font>重置</font></button>
                    </div>
                    <div class="moreSearch" style="display: none">
                        <div class="layui-inline">
                            <label class="layui-form-label">调整状态</label>
                            <select name="tzzt" lay-filter="aihao">
                                <option value=""></option>
                                <option value="">全部</option>
                                <option value="0">不需调整</option>
                                <option value="1">未调整</option>
                                <option value="2">已调整</option>
                            </select>

                        </div>
                        <div class="layui-inline">
                            <label class="layui-form-label">申请时间</label>
                            <div class="layui-input-inline">
                                <input type="text" class="layui-input" id="sqsj" name="sqsj" />
                            </div>
                        </div>

                    </div>

                    <input style="display:none" type="text" id="sqsj_start" name="sqsj_start">
                    <input style="display:none" type="text" id="sqsj_end" name="sqsj_end">


                </form>
                <div class="moreBtn"><i class="layui-icon layui-icon-triangle-d" style="color: #1E9FFF;"></i></div>
                <!--顶部按钮展示区域 【 tpl-button 】 -->
                <div class="group-button tpl-button" id="toolbar"></div>

               <!-- <div class="group-button" id="toolbar">-->

                  <!-- <a class="layui-btn layui-btn-sm layui-btn-normal add-btn">
                        <i class="layui-icon">&#x1005;</i> 添加
                    </a>-->

                </div>
                <!--列表-->
                <section class="panel panel-padding layui-card-body" >
                    <div class="pro">
                        <table id="table"  class="table text-nowrap" style="word-break:break-all; word-wrap:break-word;"></table>
                    </div>
                </section>
            </div>
        </div>
    </div>
</div>



</body>


<script type="text/javascript" th:src="@{/plugin/layui/js/layui/layui.js}"></script>
<script type="text/javascript" th:src="@{/plugin/layui/js/version.js}"></script>
<script th:src="@{/plugin/layui/js/common.js}"></script>
<div th:include="public/public_js::public_js"></div>
<div th:include="public/public_btn::public_btn"></div>
<style type="text/css">

</style>
<script th:inline="javascript">
    $(function () {
        console.info("32332")
        console.log("我来了！！ ");
        $(".moreBtn").on("click",function () {
            $(".moreSearch").toggle();
        })
    });

    //	回车查询
    document.onkeydown = function(event) {
        e = event ? event : (window.event ? window.event : null);
        if (e.keyCode == 13) {
            //执行的方法
            $('#search_button').click();
        }
    };
    var functions = [[${functions}]];
    layui.use(['list','layer','zzpUtils','jquery','laydate','tablebutton'],function () {
   /*     window.operateEvent ={
            //预检
            "click .yujian":function (e, value, row, index) {//增加地址
                console.info("增加地址");
                yujian(row.id);
            },
            //生成盘点任务
            "click .createRw":function (e, value, row, index) {

                createRw(row.id);
            },
            //关闭盘点
            "click .closeRw":function (e, value, row, index) {//激活
                closeRw(row.id);
            },
            //取消盘点任务
            "click .cancelRw":function (e, value, row, index) {//激活
                closeRw(row.id);
            },
            //盘点任务下发
            "click .xiafaRw":function (e, value, row, index) {//激活
                xiafaRw(row.id);
            },
            //库存盘点
            "click .panDian":function (e, value, row, index) {//激活
                panDian(row.id);
            },
            //生成库存调整单
            "click .createStockTz":function (e, value, row, index) {//激活
                createStockTz(row.id);
            },

        }*/

        var zzpUtils= layui.zzpUtils,
            $ = layui.jquery,
            layer=layui.layer,
            laydate = layui.laydate,
            tablebtn = layui.tablebutton;

            tablebtn.buildOnClick({
            type: 1,
            temp: $("#function_tpl"),
            functions: functions.headBtn,
            row: null,
            event: {
                searchEvent: function(){
                    console.log("点查询了");
                    zzpUtils.refreshTable("#table");
                },
                /*新增*/
                addEvent: function (data) {
                    add();
                },
                /*预检*/
                yujianEvent: function (data) {
                    yujian(data.row.id);
                },
                /*盘点任务下发*/
                xiafaRwEvent: function (data) {
                    xiafaRw(data.row.id);
                },
                /*关闭盘点*/
                closeRwEvent: function (data) {
                    closeRw(data.row.id);
                },

                /*生成库存调整单*/
                createStockTzEvent: function (data) {
                    createStockTz(data.row.id);
                },
                /*库存盘点*/
                panDianEvent: function (data) {
                    panDian(data.row.id);
                },
                /*生成盘点任务*/
                createRwEvent: function (data) {
                    createRw(data.row.id);
                },
                /*取消盘点任务*/
                cancelRw: function (data) {
                    cancelRw(data.row.id);
                },
            }
        });

        laydate.render({
            elem: '#sqsj',
            type: 'date',
            range: '~',
            done: function(value, date, endDate){
                if(value!=null && value!=""){
                    var cjsj_start=value.toString().substring(0,value.toString().indexOf("~"));
                    var cjsj_end=value.toString().substring(value.toString().indexOf("~")+1);
                    $("#sqsj_start").val(Date.parse(new Date(cjsj_start)));
                    $("#sqsj_end").val(Date.parse(new Date(cjsj_end)));
                }else {
                    $("#sqsj_start").val("");
                    $("#sqsj_end").val("");
                }

                console.log(value); //得到日期生成的值，如：2017-08-18
                console.log(date); //得到日期时间对象：{year: 2017, month: 8, date: 18, hours: 0, minutes: 0, seconds: 0}
                console.log(endDate); //得结束的日期时间对象，开启范围选择（range: true）才会返回。对象成员同上。
            }
        });





        laydate.render({
            elem: '#test5'
            ,theme: '#20a0ff'
        })
        var $table = zzpUtils.table({
            elem: '#table',
            isApi: true,
            isOperate: true,
            pagination:true,
            url: '/wmsinventoryplan/list',
            columns: [/*{
                field: '',
                checkbox: true
            },*/{
                field: 'pdbh',
                title: '盘点编号',
                align : 'center',
            },{
                field: 'show_lx',
                title: '类型',
                align : 'center',
            },{
                field: 'sqsj',
                title: '申请时间',
                align : 'center',
                formatter:function (value, row, index) {
                    return  value.substring(0, value.lastIndexOf("."));
                }
            },{
                field: 'show_qcpd',
                title: '全仓盘点',
                align : 'center'
            },{
                field: 'show_cyzt',
                title: '差异状态',
                align : 'center'
            },{
                field: 'show_dtpd',
                title: '动态盘点',
                align : 'center'
            },{
                field: 'show_kkw',
                title: '空库位',
                align : 'center'
            },{
                field: 'show_bhgdkw',
                title: '包含过渡库位',
                align : 'center'
            },{
                field: 'show_mp',
                title: '盲盘',
                align : 'center'
            },{
                field: 'show_dppdzt',
                title: '动碰盘点',
                align : 'center'
            },{
                field: 'dpkssj',
                title: '动碰开始时间',
                align : 'center',
                formatter:function (value, row, index) {
                  return  value.substring(0, value.lastIndexOf("."));
                }
            },{
                field: 'dpjssj',
                title: '动碰结束时间',
                align : 'center',
                formatter:function (value, row, index) {
                    return  value.substring(0, value.lastIndexOf("."));
                }
            },{
                field: 'show_sjpd',
                title: '随机盘点',
                align : 'center'
            },{
                field: 'show_rwzt',
                title: '盘点任务状态',
                align : 'center'
            },{
                field: 'show_zt',
                title: '盘点计划状态',
                align : 'center'
            },{
                field: 'show_tzzt',
                title: '调整状态',
                align : 'center'
            },{
                field: 'pdl',
                title: '盘点率',
                align : 'center'
            },/*{
                field:'caozuo',
                title: '可用操作',
                events:operateEvent,
                formatter:operateFormatter
            }*/],
            queryParams: function () {//查询条件
                return  zzpUtils.getFormJson($("#searchForm"));
            },
            detailFormatter: function (row,index) {
                return "这里就没有确定过11";
            },
          /*  onDblClickRow:function (row,index) {//双击展示
                btn_cha(row.id)
            },*/
            /*定义表格右侧按钮*/
            operateFormatter: operateFormatter

        });

        function btn_cha(id) {
            var zzpUtils = layui.zzpUtils,
                $ = layui.jquery,
                laydate = layui.laydate;
            zzpUtils.dialog({
                title: "客户详情",
                type: 2,
                content: "/wmsCustomerFiles/toDetail?id=" + id,
                //设置dialog大小，也可以不设置，
            });

        }

        function operateFormatter(value, row, index) {
            return [
              /*  '<a class="layui-btn layui-btn-xs layui-btn-radius layui-btn-warm yujian" >预检</a>',
                '<a class="layui-btn layui-btn-xs layui-btn-radius layui-btn-normal createRw">生成盘点任务</a>',
                '<a class="layui-btn layui-btn-xs layui-btn-radius layui-btn-danger closeRw" >关闭盘点</a>',
                '<a class="layui-btn layui-btn-xs layui-btn-radius layui-btn-warm  panDian" >库存盘点</a>',
                '<a class="layui-btn layui-btn-xs layui-btn-radius layui-btn-normal xiafaRw">盘点任务下发</a>',
                '<a class="layui-btn layui-btn-xs layui-btn-radius layui-btn-normal createStockTz">生成库存调整单</a>',
                '<a class="layui-btn layui-btn-xs layui-btn-radius layui-btn-danger cancelRw" >取消盘点任务</a>'*/
            ].join('')
        }

        $(".inline-search-btn").on('click',function () {
            zzpUtils.refreshTable("#table");
        });
         //预检
        function  yujian(id) {
            zzpUtils.confirm("确认盘点",function (index) {
                zzpUtils.action({
                    url:"/wmsinventoryplan/planWarning/"+id,
                    method:"GET",
                    success:function (data) {
                        setTimeout(function(){
                            top.layer.msg(data.title+","+data.message);
                            zzpUtils.refreshTable("#table");
                            //刷新父页面
                        },500);
                    },error: function (xhr, textStatus) {
                        console.log(textStatus);
                        console.log(xhr)
                    }
                })
            })
        }
        /*生成盘点任务*/
        function createRw(id){
            zzpUtils.confirm("确认生成盘点任务",function (index) {
                zzpUtils.action({
                    url:"/wmsinventoryplan/addPlanRw/"+id,
                    method:"GET",
                    success:function (data) {
                        setTimeout(function(){
                            top.layer.msg(data.title+","+data.message);
                            zzpUtils.refreshTable("#table");
                            //刷新父页面
                        },500);
                    },error: function (xhr, textStatus) {
                        console.log(textStatus);
                        console.log(xhr)
                    }
                })
            })
        }
        /*关闭盘点*/
        function closeRw(id){
            zzpUtils.confirm("确认关闭盘点",function (index) {
                zzpUtils.action({
                    url:"/wmsinventoryplan/closePlan/"+id,
                    method:"GET",
                    success:function (data) {
                        setTimeout(function(){
                            top.layer.msg(data.title+","+data.message);
                            zzpUtils.refreshTable("#table");
                            //刷新父页面
                        },500);
                    },error: function (xhr, textStatus) {
                        console.log(textStatus);
                        console.log(xhr)
                    }
                })
            })
        }
        /*盘点任务下发*/
        function xiafaRw(id){
            zzpUtils.dialog({
                title: "下发盘点任务",
                type: 2,
                area: ['750px', '200px'],
                content: "/wmsInventoryplanRouter/toXiafaRw?id=" + id,
                end: function () {//添加成功后刷新
                    zzpUtils.refreshTable("#table");
                }
            })

        }
        /*库存盘点*/
        function panDian(id){
           zzpUtils.dialog({
               title: "合计信息",
               type: 2,
               area:["90%"],
               content: "/wmsInventoryplanRouter/toStockPd?id=" + id,
               end: function () {//添加成功后刷新
                   zzpUtils.refreshTable("#table");
               }
           })
       }
        /*生成库存调整单*/
        function createStockTz(id){
            zzpUtils.dialog({
                title: "查看生成库存调整单",
                type: 2,
                content: "/wmsInventoryplanRouter/toStockTzd?planId=" + id,
                end: function () {//添加成功后刷新
                    zzpUtils.refreshTable("#table");
                }
            })
        }
        /*取消盘点任务*/
        function cancelRw(id){
            zzpUtils.confirm("您将选择的数据进行取消盘点任务的操作",function (index) {
                zzpUtils.action({
                    url:"/wmsinventoryplan/closePlanRw/"+id,
                    method:"GET",
                    success:function (data) {
                        setTimeout(function(){
                            top.layer.msg(data.title+","+data.message);
                            zzpUtils.refreshTable("#table");
                            //刷新父页面
                        },500);
                    },error: function (xhr, textStatus) {
                        console.log(textStatus);
                        console.log(xhr)
                    }
                })
            })
        }


        $(".edit-btn").on('click',function () {
            var $rows = $table.bootstrapTable('getSelections');
            if($rows.length != 1){
                layer.msg("请选择一条进行编辑");
            }else{
                var id = $.map($rows,function (row) {
                    return row.id;
                })
                zzpUtils.dialog({
                    title: "修改客户档案",
                    type: 2,
                    content: "/wmsCustomerFiles/baseSelectDetail?id=" + id,
                    end: function () {//添加成功后刷新
                        zzpUtils.refreshTable("#table");
                    }

                })
            }


        })

        //新增
        function add() {
            zzpUtils.dialog({
                title:"新增盘点",
                type:2,
                content: "/wmsInventoryplanRouter/toAddInventoryPlan",
                area: ['700px', '550px'],
                btn:[],
                end: function () {//添加成功后刷新
                    zzpUtils.refreshTable("#table");
                }

            });
        }


        /*表格右侧按钮*/
        function operateFormatter(value, row, index) {
            var button = '<a class="tooltip2" id="tooltip' + row.id + '" data-tooltip-content="#tool' + row.id + '" id="btn_start">  更多</a>'
                + '<div class="tooltip_templates">'
                + '<span id="tool' + row.id + '">';
             var buttons ="";
             var buttons2 ="";
             var buttons1 ="";
            for (var i = 0; i < functions.tableBtn.length; i++) {
                var btn = '<a class="layui-btn layui-btn-sm layui-btn-normal" lay-event="' + functions.tableBtn[i].event + '">'
                    + functions.tableBtn[i].name
                    + '</a>';
               /* button += btn;*/
                var item = functions.tableBtn[i];
                var Disable = '<button class="layui-btn layui-btn-xs layui-btn-disabled" disabled lay-event="' + item.event + '">' + item.name + '</button>';
                var Enable = '<button class="layui-btn layui-btn-xs layui-btn-normal" lay-event="' + item.event + '">' + item.name + '</button>';
                if (item.name =='预检'||item.name == '库存盘点'||item.name == '生成库存调整单') {
                    switch (item.name) {
                        case '预检':
                            buttons2 += '<button class="layui-btn layui-btn-xs layui-btn-danger" lay-event="' + item.event + '">' + item.name + '</button>';
                            break;
                        case '库存盘点':
                            if (row.rwzt == 1)
                                buttons2 += Enable;
                            else
                                buttons2 += Disable;
                            break;
                        case '生成库存调整单':
                            if (row.cyzt == 2)
                                buttons2 += Enable;
                            else
                                buttons2 += Disable;
                            break;
                    }
                }else {
                    switch (item.name) {
                        case '关闭盘点':
                            if (row.rwzt == 0)
                                buttons1 += Enable;
                            else
                                buttons1 += Disable;

                            break;
                        case '生成盘点任务':
                            if (row.rwzt == 0 && row.zt == 0)
                                buttons1 += Enable;
                            else
                                buttons1 += Disable;
                            break;
                        case '取消盘点任务':
                            if (row.zt == 0 && row.rwzt == 1)
                                buttons1 += Enable;
                            else
                                buttons1 += Disable;
                            break;
                       /* case '库存盘点':
                            if (row.rwzt == 1)
                                buttons1 += Enable;
                            else
                                buttons1 += Disable;
                            break;
                        case '生成库存调整单':
                            if (row.cyzt == 2)
                                buttons1 += Enable;
                            else
                                buttons1 += Disable;
                            break;*/
                        case '盘点任务下发':
                            if (row.rwzt == 1)
                                buttons1 += Enable;
                            else
                                buttons1 += Disable;
                            break;
                        default:
                            buttons1 += Enable;

                    }
                }



/*
                if (functions.tableBtn[i].name == '预检') {
                    button += btn;
                }

                if (row.rwzt==0) {
                    if (functions.tableBtn[i].name == '关闭盘点') {
                        button += btn;
                    }
                }

                if( row.rwzt==0 && row.zt==0){

                    if (functions.tableBtn[i].name == '生成盘点任务') {
                        button += btn;
                    }
                }
                if(row.zt==0 && row.rwzt==1){
                    if (functions.tableBtn[i].name == '取消盘点任务') {
                        button += btn;
                    }
                }
                if(row.rwzt==1){
                    if (functions.tableBtn[i].name == '库存盘点') {
                        button += btn;
                    }
                }
                if(row.cyzt==2){
                    if (functions.tableBtn[i].name == '生成库存调整单') {
                        button += btn;
                    }
                }
                if(row.rwzt==1){
                    if (functions.tableBtn[i].name == '盘点任务下发') {
                        button += btn;
                    }
                }*/
            }
        /*    buttons1 += '</span>'
                + '</div>';
            return buttons1;*/
            console.info("buttons2");
console.info(buttons2);
            buttons += buttons2;
            buttons += button;
            buttons += buttons1;
            buttons += '</span></div>';
            return buttons;

        }

    });
</script>
</html>